package com.echat.messagesender.sender.bean;

import com.echat.commonlib.exception.exc.ValidateFailedException;
import com.echat.messagesender.sender.util.StringUtils;
import lombok.Data;

import java.io.Serializable;

/**
 * Created by chenmohan on 2018/08/15
 *
 * @description
 */
@Data
public class EchatSendEmailInfo implements Serializable {

    /**
     * 【必填】客户id,消息发送服务分配的唯一标识
     */
    private Long userId;

    /**
     * 【选填】平台账号id,该值不为null时,使用指定的账号发送邮件
     */
    private Long platformAccountId;

    /**
     * 【必填】邮件名
     */
    private String title;

    /**
     * 邮件正文内容：文本内容,模板id不为空时该字段无效
     */
    private String content;

    /**
     * 【必填】邮件接收人
     */
    private String[] receivers;

    /**
     * 抄送(SMTP协议有效)
     */
    private String[] ccReceivers;

    /**
     * 暗抄送(SMTP有效)
     */
    private String[] bccReceivers;

    /**
     * 回执收件人(SMTP有效)
     */
    private String replyEmail;

    /**
     * 邮件模板id
     */
    private String templateId;

    /**
     * 使用邮件模板 替换的参数map
     */
    private String vars;

    public void check() {
        if(this.userId == null){
            throw new ValidateFailedException("'userId' must not be null");
        }
        if(StringUtils.isEmpty(this.title)){
            throw new ValidateFailedException("'title' must not be null or an empty string");
        }
        if(this.receivers == null || this.receivers.length == 0){
            throw new ValidateFailedException("'receivers' 至少有1个email地址");
        }
        if( content == null && templateId == null ){
            throw new ValidateFailedException("邮件内容(content)或者模板ID(templateId) 其中必填1个");
        }
    }

}
